home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra / disp186b.zip / WD90C3X.ASM < prev    next >
Assembly Source File  |  1993-04-09  |  12KB  |  386 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file WD90C31.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ; Copyright (C) 1993 John Horigan, 870 E. El Camino Real #161, Mtn View, CA 94040
  7. ;
  8. ; This file is distributed under the terms listed in the document
  9. ; "copying.dj", available from DJ Delorie at the address above.
  10. ; A copy of "copying.dj" should accompany this file; if not, a copy
  11. ; should be available from where this file was obtained.  This file
  12. ; may not be distributed without a verbatim copy of "copying.dj".
  13. ;
  14. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  15. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. ;--------------------------------------------------------------------------
  17.  
  18.     .386
  19. include grdriver.inc
  20. cseg    segment byte public use16 'code'
  21.     assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  22.  
  23.  
  24. ;--------------------------------------------------------------------------
  25. ; DRIVER HEADER
  26. ;  The following entries MUST match the structure and constant
  27. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  28. ;  The mode word should contain the following bitfields:
  29. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  30. ;     - the adapter type field should be specified
  31. ;     - the memory size field should be specified
  32. ;     - the paging mode field should be specified
  33. ;  The mode set routine will OR in the plane bitfield as it will
  34. ;  change when different color number modes are requested.
  35. ;--------------------------------------------------------------------------
  36.  
  37.     dw    offset mode_set_routine
  38.     dw    offset paging_routine
  39. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_RW_64K
  40. ;
  41. ; The 'def_xx' fields are filled in by go32 from the corresponding
  42. ; fields of the 'GO32' environment variable
  43. ;
  44. def_tw  dw    80        ; text width
  45. def_th  dw    25        ; text height
  46. def_gw  dw    640        ; graphics width
  47. def_gh  dw    480        ; graphics height
  48. def_nc  dw    16        ; graphics colors
  49.     dw    offset driver_init_routine
  50.     dw    offset text_mode_table
  51.     dw    offset graphics_mode_table
  52.  
  53. ;
  54. ; Biggest text and graphics sizes
  55. ;
  56. Max_TW  equ    132
  57. Max_TH  equ    50
  58. Max_GWn equ    800        ; non interlaced!!!
  59. Max_GHn equ    600
  60. Max_GW  equ    1280        ; may be interlaced
  61. Max_GH  equ    1024
  62.  
  63.  
  64. ;--------------------------------------------------------------------------
  65. ; TABLE OF SUPPORTED TEXT MODES
  66. ;    - keep sorted by size
  67. ;    - end with an all 0 entry
  68. ;    - BIOS field = 0xff disables it
  69. ;    - fields:
  70. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  71. ;--------------------------------------------------------------------------
  72. text_mode_table        label word
  73.     dw    80,    25,    2,    007h +  00000h
  74.     dw    40,    25,    16,    001h +  00000h
  75.     dw    80,    25,    16,    003h +  00000h
  76.     dw    80,    34,    16,    041h +    00000h
  77.     dw    80,    43,    16,    067h +    00000h
  78.     dw    80,    50,    16,    066h +  00000h
  79.     dw    132,    25,    16,    055h +  00000h
  80.     dw    132,    28,    16,    047h +  00000h
  81.     dw    132,    43,    16,    054h +  00000h
  82.     dw    132,    44,    16,    021h +  00000h
  83.     dw    132,    50,    16,    069h +  00100h
  84.     dw    0,    0,    0,    000h +  00000h
  85.  
  86.  
  87. ;--------------------------------------------------------------------------
  88. ; TABLE OF SUPPORTED GRAPHICS MODES
  89. ;    - keep sorted first by colors then by size
  90. ;    - end with an all 0 entry
  91. ;    - BIOS field = 0xff disables it
  92. ;    - fields:
  93. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  94. ;--------------------------------------------------------------------------
  95. graphics_mode_table    label word
  96.     dw    320,    200,    16,    00dh +  00000h
  97.     dw    640,    200,    16,    00eh +  00000h
  98.     dw    640,    350,    16,    010h +  00000h
  99.     dw    640,    480,    16,    012h +  00000h
  100.     dw    800,    600,    16,    058h +  00000h
  101.     dw    1024,    768,    16,    05dh +  00000h
  102.     dw    1280,    1024,    16,    064h +    00000h
  103.     dw    320,    200,    256,    013h +  00000h
  104.     dw    640,    400,    256,    05eh +  00000h
  105.     dw    640,    480,    256,    05fh +  00000h
  106.     dw    800,    600,    256,    05ch +  00000h
  107.     dw    1024,    768,    256,    060h +  00000h
  108.     dw    0,    0,    0,    000h +  00000h
  109.  
  110.  
  111. ;--------------------------------------------------------------------------
  112. ; TABLE OF SPECIAL SETUP PROCEDURES
  113. ;  You may need such procedures for:
  114. ;     -- reloading fonts on standard EGA or VGA for
  115. ;     higher resolution text modes
  116. ;     -- enable HiColor mode of some Super VGAs
  117. ;     -- Handle the parameter passing conventions of the VESA BIOS
  118. ;     -- put VGA into 256 color plane mode ("MODE X")
  119. ;     -- etc...
  120. ;  There should be one entry in the table for every non-zero
  121. ;  'setup_procedure_index' in the text and graphics mode tables.
  122. ;  The first entry in the table belongs to index 100h, and so on.
  123. ;  The special setup procedure is invoked via a near call.
  124. ;
  125. ;  Entry: DI=address of the mode record from the text or graphics
  126. ;      table to set up.
  127. ;
  128. ;  Exit:  Adapter configured
  129. ;      BX=driver mode word as it should be returned by the mode set
  130. ;         routine. Typically it involves picking up the mode word
  131. ;         from the header and OR-ing in the appropriate bitplane mode
  132. ;         bitfield. (This is not needed for text modes)
  133. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  134. ;
  135. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  136. ;--------------------------------------------------------------------------
  137. special_setup_table    label word
  138.     dw    offset  VGA_50row_mode_set
  139.  
  140. ;
  141. ; Routine to set up VGA 132x50 row mode
  142. ; interface is described above
  143. ;
  144. VGA_50row_mode_set    proc    near
  145.     mov    ax,055h            ; set 132x25 mode
  146.     int    10h
  147.     xor    bx,bx
  148.     mov    ax,1112h        ; load 8x8 font
  149.     int    10h
  150.     ret
  151. VGA_50row_mode_set    endp
  152.  
  153.  
  154. ;--------------------------------------------------------------------------
  155. ; DRIVER INIT ROUTINE
  156. ;  called once after the driver is loaded
  157. ;  may do one or more of the followings:
  158. ;    - check for proper board type
  159. ;    - check amount of RAM on board, and:
  160. ;    -- update word in header to reflect correct amount
  161. ;    -- disable modes in the tables for which there is not enough RAM
  162. ;    - check for special equipment (HiColor DAC, etc...)
  163. ;
  164. ;  Entry: nothing
  165. ;
  166. ;  Exit:  AX=status:
  167. ;       non-zero: OK,
  168. ;       0: something went wrong (e.g. wrong adapter, etc..)
  169. ;      BX,CX,DX may be trashed
  170. ;
  171. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  172. ;--------------------------------------------------------------------------
  173. driver_init_routine    proc    far
  174.     mov    dx,03ceh
  175.     mov    ax,0e0bh
  176.     out    dx,ax            ; enable second bank register
  177.     mov    dx,03c5h
  178.     mov    ax,0ff11h        ; set bank registers for R/W banking
  179.     out    dx,ax            ;  at B000:0000 - B000:FFFF
  180.     ret
  181. driver_init_routine    endp
  182.  
  183.  
  184. ;--------------------------------------------------------------------------
  185. ; MODE SET ROUTINE
  186. ;  sets up a text or graphics mode as close as possible to the one
  187. ;  reguested by the user with regard to number of colors and size.
  188. ;
  189. ;  Entry: AX=mode selection
  190. ;     0 = 80x25 text
  191. ;     1 = default text
  192. ;     2 = text CX cols by DX rows
  193. ;     3 = biggest text
  194. ;     4 = 320x200 graphics
  195. ;     5 = default graphics
  196. ;     6 = graphics CX width by DX height
  197. ;     7 = biggest non-interlaced graphics
  198. ;     8 = biggest graphics
  199. ;     9 = graphics BX colors, CX width by DX height
  200. ;
  201. ;  Exit: BX=driver mode flag
  202. ;     CX=width (in pixels or characters)
  203. ;     DX=height
  204. ;
  205. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  206. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  207. ;     MUCH TABLE DRIVEN
  208. ;--------------------------------------------------------------------------
  209. mode_set_routine    proc    far
  210.     push    ds
  211.     push    di
  212.     push    si
  213.     mov    si,cs
  214.     mov    ds,si
  215.     cmp    ax,9
  216.     jbe    DoIt
  217.     jmp    Exit
  218. DoIt:    add    ax,ax
  219.     mov    si,ax
  220.     jmp    WORD PTR mode_set_table[si]
  221. mode_set_table  label    word
  222.     dw    offset mode_0
  223.     dw    offset mode_1
  224.     dw    offset mode_2
  225.     dw    offset mode_3
  226.     dw    offset mode_4
  227.     dw    offset mode_5
  228.     dw    offset mode_6
  229.     dw    offset mode_7
  230.     dw    offset mode_8
  231.     dw    offset mode_9
  232. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  233.     mov    bx,def_nc
  234.     mov    cx,80
  235.     mov    dx,25
  236.     jmp    Lookup
  237. mode_1: mov    si,offset text_mode_table    ; default text
  238.     mov    bx,def_nc
  239.     mov    cx,def_tw
  240.     mov    dx,def_th
  241.     jmp    Lookup
  242. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  243.     mov    bx,def_nc
  244.     jmp    Lookup
  245. mode_3: mov    si,offset text_mode_table    ; biggest text
  246.     mov    bx,def_nc
  247.     mov    cx,Max_TW
  248.     mov    dx,Max_TH
  249.     jmp    Lookup
  250. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  251.     mov    bx,def_nc
  252.     mov    cx,320
  253.     mov    dx,200
  254.     jmp    Lookup
  255. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  256.     mov    bx,def_nc
  257.     mov    cx,def_gw
  258.     mov    dx,def_gh
  259.     jmp    Lookup
  260. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  261.     mov    bx,def_nc
  262.     jmp    Lookup
  263. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  264.     mov    bx,def_nc
  265.     mov    cx,Max_GWn
  266.     mov    dx,Max_GHn
  267.     jmp    Lookup
  268. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  269.     mov    bx,def_nc
  270.     mov    cx,Max_GW
  271.     mov    dx,Max_GH
  272.     jmp    Lookup
  273. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  274. ;
  275. ; At this point:
  276. ;   SI points to the table to search (text or graphics)
  277. ;   BX has colors
  278. ;   CX has width
  279. ;   DX has height
  280. ;
  281. Lookup: xor    ax,ax                ; last color number seen
  282. Find_C: cmp    [si+4],ax            ; last color number == this?
  283.     je    Same_C
  284.     jb    Prev_C                ; end of table -- use last color
  285.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  286.     je    Prev_C                ; not -- use last color
  287.     mov    ax,[si+4]            ; record color number
  288.     mov    di,si                ; start of entries w/ this color
  289.     cmp    ax,bx                ; enough colors ?
  290.     jae    Find_S
  291. Same_C: add    si,8
  292.     jmp    Find_C
  293. Prev_C: or    ax,ax                ; found any color at all?
  294.     je    Exit
  295. ;
  296. ; At this point:
  297. ;   DI points into the table to the first entry with the desired color
  298. ;      number (either it has enough colors or it is the highest color
  299. ;      number supported by the driver). Additionally, at least the
  300. ;      first (= smallest size) entry for this color is valid (has a
  301. ;      valid BIOS number).
  302. ;   AX has the color number adjusted for the driver
  303. ;   CX has width
  304. ;   DX has height
  305. ;
  306. Find_S: cmp    [di+4],ax            ; still the same color #?
  307.     jne    Prev_S
  308.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  309.     je    Prev_S
  310.     cmp    [di],cx
  311.     jb    Next_S
  312.     cmp    [di+2],dx
  313.     jae    GotIt
  314. Next_S: add    di,8
  315.     jmp    Find_S
  316. Prev_S: sub    di,8
  317. ;
  318. ; At this point:
  319. ;   DI points to the table entry we want to set up
  320. ;
  321. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  322.     or    ah,ah                ; special ?
  323.     je    doBIOS
  324.     mov    al,ah
  325.     xor    ah,ah
  326.     dec    ax
  327.     add    ax,ax
  328.     mov    si,ax
  329.     call    WORD PTR special_setup_table[si]
  330.     jmp    RetVal
  331. doBIOS: int    10h
  332.     mov    bx,GRD_1_PLANE
  333.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  334.     je    doFLAG
  335.     mov    bx,GRD_4_PLANES
  336.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  337.     je    doFLAG
  338.     mov    bx,GRD_8_PLANES
  339.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  340.     je    doFLAG
  341.     mov    bx,GRD_16_PLANES
  342.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  343.     je    doFLAG
  344.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  345. doFLAG: or    bx,mode_W
  346. RetVal: mov    cx,[di]
  347.     mov    dx,[di+2]
  348. Exit:    pop    si
  349.     pop    di
  350.     pop    ds
  351.     ret
  352. mode_set_routine    endp
  353.  
  354.  
  355. ;--------------------------------------------------------------------------
  356. ; PAGING ROUTINE
  357. ;
  358. ;  Entry: AH=read page
  359. ;      AL=write page
  360. ;
  361. ;  Exit: VGA configured.
  362. ;     AX,BX,CX,DX,SI,DI may be trashed
  363. ;
  364. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  365. ;     This code must be relocatable and may not reference any data!
  366. ;--------------------------------------------------------------------------
  367.     assume  ds:nothing, es:nothing
  368.  
  369. paging_routine  proc    far
  370.     shl    ah,4 ; WD90C3x offset registers have 4k granularity 
  371.     shl    al,4 ; => multiply by 16 to get normal VGA 64k bank granularity
  372.     mov    bh,al
  373.     mov    bl,0ah            ; write bank gets PR0B index code
  374.     mov    al,09h            ; read bank gets PR0A index code
  375.     mov    dx,03ceh        ; load graphics index register number
  376.     out    dx,ax            ; set PR0A (read bank)
  377.     mov    ax,bx
  378.     out    dx,ax            ; set PR0B (write bank)
  379.     ret
  380. paging_routine  endp
  381.  
  382.  
  383. cseg    ends
  384.     end
  385.  
  386.